package com.ddzj.scaffold.service.impl;


import com.ddzj.scaffold.service.DateService;
import com.ddzj.scaffold.utils.IdUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ddzj.scaffold.entity.User;
import com.ddzj.scaffold.mapper.UserMapper;
import com.ddzj.scaffold.service.UserService;
import org.springframework.transaction.annotation.Transactional;

/**
*
* <p>
*  用户表接口的实现
* </p>
*
* <p>
*   Copyright: 2024 . All rights reserved.
* </p>
* <p>
*   Company: yangzibo
* </p>
* <p>
*   CreateDate:2024-04-11 12:11:16
* </p>
*
* @author default
* @history Mender:default；Date:2024-04-11 12:11:16；
*/
@Service
public class UserServiceImpl  extends ServiceImpl<UserMapper, User> implements UserService  {

    @Autowired
    private DateService dateService;

    @Override
    public Long findExistsUserByAccount(String account) {
        return this.baseMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getAccount, account));
    }

    @Override
    @Transactional
    public void saveRegisterUserInfo(User user) {
        user.setCode(IdUtils.getSnowflakeIdWorkerId());
        user.setLoginErrors(0);
        this.save(user);
    }

    @Override
    public User findByAccount(String account) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getAccount, account));
    }

}